<template>
	<view class="padbottom10">
		<!--  -->
		<ben></ben>
		<!--  -->
		<view class="background_f">
			<uni-segmented-control :current="current" :values="tabList" @clickItem="onClickItem" styleType="text"
				activeColor="#FFAD4C"></uni-segmented-control>
		</view>
		<view class="empty" style="margin-top: 300rpx;" v-if="list.length == 0">
			<u-empty mode="data" icon="https://cdn.uviewui.com/uview/empty/data.png">
			</u-empty>
		</view>
		<view v-else>
			<view class="mintop20 min30_rl background_f rad2" v-for="(item,index) in list" :key="index">
				<view class="row padright30 just_cont_spacebet align_item_c size24 col6 font500">
					<view class="colf size26 font600" :class="item.status == 0 ? 'income' : 'refund'">
						{{ current == 0 ? '收入' : '退款' }}
					</view>
					{{ item.create_time }}
				</view>
				<view class="pad20_tb min30_rl column size28 col3 font500">
					订单编号：{{ item.order_no }}
					<view class="row just_cont_spacebet mintop20">
						<view class="row">
							积分：
							<view style="color: #DB3634;">
								{{ item.socre }}
							</view>
						</view>
						<!-- <view class="row">
							总积分：
							<view style="color: #DB3634;">
								{{ item.totalintegral }}
							</view>
						</view> -->
					</view>
				</view>
			</view>
			<view style="padding: 40rpx 0;"><u-loadmore :status="status" /></view>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				tabList: ['收入', '退款'],
				user_id: '',
				current: 0,
				page: 1,
				status: 'nomore',
				loadmore: [],
				list: []
			}
		},
		onShow() {
			//当前页面展示的时候他就执行该生命周期
			this.user_id = uni.getStorageSync('user_id');
			const token = uni.getStorageSync('token');
			if (token) {
				//如果存在token
				this.getOrderList()
				//按正常逻辑来讲 登录成功 我们是不是需要向服务器获取用户的信息？
				//那么我们一起来获取用户信息
			} else {

				uni.showToast({
					title: '您还未登录，正在前往登录',
					icon: 'none'
				})
				setTimeout(function() {
					uni.navigateTo({
						url: "/mypackage/user/login"
					})
				}, 1000)
			}
		},
		onReachBottom() {
			if (this.page < 0) return;
			this.status = 'loading';
			this.page = ++this.page
			this.getOrderList()
			setTimeout(() => {
				console.log(this.loadmore);
				if (this.loadmore.length == 0) this.status = 'nomore';
				else this.status = 'loading';
			}, 1000)
		},
		methods: {
			onClickItem(e) {
				if (this.current != e.currentIndex) {
					this.current = e.currentIndex;
				}
				this.getOrderList()
			},
			async getOrderList() {
				var order_status = ''
				if (this.current == 0) {
					order_status = 1
				} else {
					order_status = 2
				}
				let {
					code,
					message,
					data
				} = await this.$com.fetchGet("shop/shop_SocreDetails/" + this.user_id, {
					type: order_status,
					page: this.page
				})
				if (code == 200) {
					if (this.page != 1) {
						this.loadmore = data.items
						for (var i = 0; i < data.items.length; i++) {
							this.list.push(data.items[i]); // 加载的数据追加在上一页后面
						}
					} else {
						this.loadmore = data.items
						this.list = data.items
					}
				} else {
					console.log(message);
				}
			}
		}
	}
</script>

<style scoped lang="less">
	.income {
		background: #FFAD4C;
		border-radius: 20rpx 0rpx 20rpx 0rpx;
		padding: 6rpx 20rpx;
	}

	.refund {
		background: #3B7CDF;
		border-radius: 20rpx 0rpx 20rpx 0rpx;
		padding: 6rpx 20rpx;
	}
</style>